package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsAdmin;
import com.qf.service.AdminService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * projectName: wokepase1
 *
 * @author: 强力
 * time: 2021/9/14 14:06
 * description:
 */
@RestController
@RequestMapping("/admin")
@CrossOrigin("*")
public class AdminController {

    @Autowired
    private AdminService adminService;
    /**
     *
     * @param page  当前页
     * @param limit 每页显示的条数
     * @param username 查询条件用户名
     * @param sort 查询条件
     * @param order
     * @return
     */
    @RequestMapping("/list")
    public  Object adminlist(Integer page,Integer limit,String username,String sort, String  order){
        IPage<DtsAdmin> adminIPage=adminService.findByPage(page,limit,username,sort,order);
        //封装返回数据
        Map<String,Object> data=new HashMap<>();
        data.put("total",adminIPage.getTotal());
        data.put("items",adminIPage.getRecords());
return ResponseUtil.ok(data);
}

@RequestMapping("/create")
    public  Object create(@RequestBody DtsAdmin admin){

     admin = adminService.insert(admin);

    return ResponseUtil.ok(admin);
}


@RequestMapping("/delete")
    public  Object delete(@RequestBody DtsAdmin admin){
        adminService.delete(admin);
return ResponseUtil.ok();
}

@RequestMapping("/update")
    public Object update(@RequestBody DtsAdmin admin){

       admin=adminService.update(admin);

       return ResponseUtil.ok(admin);
}

}
